package edu.fudan.jwxt.utils;

import edu.fudan.jwxt.Exception.ServiceException;
import edu.fudan.jwxt.common.Constants;

import static edu.fudan.jwxt.common.RoleConstant.AdministratorStr;

public class RoleCheckUtil {
    public static void CheckUserAdmin(){
        if(! TokenUtils.getCurrentUser().ProduceRole().equals(AdministratorStr) && ! TokenUtils.getCurrentUser().ProduceRole().equals("00123"))
            throw new ServiceException(Constants.CODE_401,"权限不足 !");
    }

    public static void CheckUserUID(String UID){
        if(! TokenUtils.getCurrentUser().getUid().equals(UID))
            CheckUserAdmin();
    }

    public static void CheckUserTeacher(){
        if(! UserFormat.IsTeacherID(TokenUtils.getCurrentUser().getUid())){
            CheckUserAdmin();
        }
    }

}
